<?php

namespace App\Admin\Controllers\SysManage;

use App\Http\Controllers\Controller;

use App\Models\SysPlatform;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Row;
use Illuminate\Http\Request;
use Encore\Admin\Controllers\ModelForm;

class SysPlatformController
{
    use ModelForm;

    public function index()
    {
        return Admin::content(function(Content $content){
            $content->header( '客户端平台信息配置');
            $content->body($this->grid()->render());

        });
    }
    public function edit($id) {
        return Admin::content(function (Content $content) use ($id) {
            $content->body($this->form()->edit($id));
        });
    }
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('新增');
            $content->description('新增接入平台');

            $content->body($this->form());
        });
    }
    protected function grid(){
        return Admin::grid(SysPlatform::class,function(Grid $grid){
            $grid->id('编号')->sortable();
            $grid->platform_name('平台名称');
            $grid->enable('状态')->switch([
                'on'  => ['value' => 1, 'text' => '启用', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '禁用', 'color' => 'success'],
            ]);

            $grid->platform_code('平台唯一标识码')->editable();;
            $grid->sign_key('平台签名秘钥')->editable();
            $grid->client_ip('客户端地址')->editable();

            $grid->disableExport();

        });
    }

    protected function form()
    {
        return Admin::form(SysPlatform::class, function (Form $form) {
            $form->display('id', '编号');
            $form->text('platform_name','平台名称');
            $form->switch('enable','状态');
            $form->text('platform_code', '平台唯一标识码');
            $form->text('sign_key', '平台签名秘钥');
            $form->text('client_ip','平台签名秘钥');
        });
    }
}
